package cn.edu.scujj.dao;
import cn.edu.scujj.bean.BookType;
import cn.edu.scujj.utils.DButil;
import java.sql.Connection;
import java.sql.*;
import java.util.ArrayList;
import java.util.List;

public class TongjiDao {
    public List<BookType> findAll() {
        Connection conn = DButil.getConnection();
        String sql = "select * from librarysystem.booktype_info";
        Statement stmt = null;
        List<BookType> list = new ArrayList<>();
        try {
            stmt = conn.createStatement();
            ResultSet rs = stmt.executeQuery(sql);
            while (rs.next()) {
                BookType bookType = new BookType();
                bookType.setTypeId(rs.getInt("booktype_id"));
                bookType.setTypeName(rs.getString("booktype_name"));
                list.add(bookType);
            }
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            DButil.close(conn);
        }
        return list;
    }

}
